<template>
	<view>
		<view class="pageTitle">
			忘记密码
		</view>
		<view class="loginBlock">
			<u-field v-model="pwd" @input="passwordOldChange" type="password" placeholder="旧密码"
				:error-message="errorMessageOldPassword" class="inputBox">
			</u-field>
			<u-field v-model="newPwd" @input="passwordNewChange" type="password" placeholder="新密码(至少6位密码,包含数字字母)"
				:error-message="errorMessageNewPassword">
			</u-field>
			<u-button type="success" shape="circle" :custom-style="buttonStyle" @click="toChangePwd">提交</u-button>
		</view>
		<u-toast ref="uToast" />
		<u-no-network></u-no-network>
	</view>
</template>

<script>
	import {
		buttonStyle
	} from "@/utils/buttonStyle.js";
	export default {
		data() {
			return {
				pwd: "",
				newPwd: "",
				errorMessageNewPassword: "",
				errorMessageOldPassword: "",
				buttonStyle
			}
		},
		onReady() {

		},
		onShow() {

		},
		methods: {
			passwordOldChange(e) {
				if (e != "") {
					this.errorMessageOldPassword = ""
				}
			},
			passwordNewChange(e) {
				if (e != "") {
					this.errorMessageNewPassword = ""
				}
			},
			toChangePwd() {
				let that = this
				if (that.pwd == "") {
					uni.showToast({
						icon: "none",
						title: '请输入您的旧密码',
						duration: 2000,
					})

					return;
				}
				if (that.newPwd == "" && !that.isVerifyLogin) {
					uni.showToast({
						icon: "none",
						title: '请输入您的新密码',
						duration: 2000,
					})
					return;
				}
				let params = {
					"newPwd": that.newPwd,
					"pwd": that.pwd,
				}
				that.$api.changePwd(params).then((res) => {
					uni.showToast({
						title: '修改成功',
						icon: "success",
						duration: 2000,
						success: () => {
							setTimeout(() => {
								uni.navigateTo({
									url: '/pages/mine/index'
								})
							}, 2000)
						}
					})
				})
			}
		}
	};
</script>

<style scoped lang="scss">
	.actions {
		width: 670rpx;
		margin: 60rpx auto;
	}
</style>